package com.heima.reggie.service.impl;

import com.heima.reggie.service.SmsService;
import com.heima.reggie.utils.ValidateCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.security.Key;
import java.util.concurrent.TimeUnit;
@Slf4j
@Service
public class SmsServiceImpl implements SmsService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public String senCode(String phone) {
        String code = ValidateCodeUtils.generateValidateCode4String(6);

        //session.setAttribute(phone,code);
        String Key = "login_"+ phone;

        redisTemplate.opsForValue().set(Key,code,5, TimeUnit.MINUTES);
        log.debug("存入到redis的手机号{}验证码{}",phone,code);
        return code;
    }
}
